<template>
  <div>
    <el-row class="box">
      <el-form label-position="right" label-width="110px">
        <el-col :span="8">
          <el-form-item label="取件任务编号：">
            <el-input v-model="formDate.id"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="订单编号：">
            <el-input v-model="formDate.orderId"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="所属营业部:">
            <el-cascader
                  v-model="form.startAgencyName"
                  :options="tree"
                  :props="props"
                  @change="change1"
                  :filterable="true"
                  placeholder="请选择所属营业部"
                ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col  :span="8">
          <el-form-item label="签收状态：">
            <el-select v-model="formDate.signStatus" placeholder="请选择">
              <el-option
                v-for="item in assignedStatus1"
                :key="item.value"
                :label="item.lable"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预计完成时间：">
            <el-date-picker
              v-model="value1"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 250px"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="实际完成时间：">
            <el-date-picker
              v-model="value2"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 250px"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务分配状态：">
            <el-select v-model="formDate.assignedStatus" placeholder="请选择">
              <el-option
                v-for="item in assignedStatus"
                :key="item.value"
                :label="item.lable"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col >
        <el-col :span="12">
          <el-button type="warning" plain @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
        </el-col>
      </el-form>
    </el-row>
    <el-row class="centen">
      <el-col :span="2"
        ><el-button @click="getPickup(form)">全部</el-button></el-col
      >
      <el-col :span="2"
        ><el-button @click="getPickup({ ...form, status: 1 })"
          >新任务</el-button
        ></el-col
      >
      <el-col :span="2"
        ><el-button @click="getPickup({ ...form, status: 2 })"
          >已完成</el-button
        ></el-col
      >
    </el-row>
    <div class="button">
      <el-button type="warning" plain>人工分配</el-button>
      <el-table :data="Data" style="width: 100%; font-size: 12px" :disabled="true" >
        <el-table-column type="selection"> </el-table-column>
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="id" label="取件任务编号" width="150">
        </el-table-column>
        <el-table-column prop="agencyName" label="所属机构"> </el-table-column>
        <el-table-column
          prop="assignedStatus"
          label="任务分配状态"
          width="100"
          :formatter="formatter"
        >
        </el-table-column>
        <el-table-column prop="courierName" label="快递员姓名">
        </el-table-column>
        <el-table-column prop="orderId" label="订单编号"> </el-table-column>
        <el-table-column prop="estimatedStartTime" label="预计开始时间">
        </el-table-column>
        <el-table-column prop="estimatedEndTime" label="预计完成时间">
        </el-table-column>
        <el-table-column prop="actualEndTime" label="实际完成时间">
        </el-table-column>
      </el-table>
      <el-pagination
        @current-change="handleCurrentChange"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>

import { getPickupPageApi } from '@/api/pickUptask'
import { gettreeApi } from "@/api/register";
export default {
  name: "pickUptask",
  data() {
    return {
      form: {
        page: 1,
        pageSize: 10,
        taskType: 2,
      },
      formDate: {
       
      },
      props: {
        expandTrigger: "hover",
        label: "name",
        value: "id",
        checkStrictly: true,
      },
      tree: [],
      Data: [{}],
      value1: "",
      value2: "",
      total: 0,
      assignedStatus: [
        {
          lable: "已分配",
          value: 1,
        },
        {
          lable: "待人工分配",
          value: 2,
        },
      ],
      assignedStatus1: [
        {
          lable: "已签收",
          value: 1,
        },
        {
          lable: "拒签",
          value: 2,
        },
      ],
    };
  },
  created() {
    this.getPickup(this.form);
    this.getcount()
  },
  methods: {
    async getcount() {
      const res = await gettreeApi(this.form);
      console.log(JSON.parse(res.data));
      this.tree = JSON.parse(res.data);
    },
    change1(a) {
      // console.log(a);
      this.form.startAgencyName = "";
      this.form.agencyId = a[a.length - 1] || [];
    },
    async getPickup(data) {
      const res = await getPickupPageApi(data);
      this.total = +res.data.counts;
      this.Data = res.data.items;
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getPickup(this.form)
    },
   async search() {
     const res = await getPickupPageApi({...this.form, ...this.formDate})
     console.log(res);
     this.total = +res.data.counts;
      this.Data = res.data.items;
    },
    reset() {
      this.form = {
        page: 1,
        pageSize: 10,
        taskType: 1,
      };
      this.getPickup(this.form);
    },
    formatter(a, b, c) {
      if (c === 2) {
        return "已分配";
      } else if (c === 3) {
        return "待人工分配";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  background-color: #fff;
  height: 204px;
  padding: 20px;
  margin-bottom: 20px;
  .el-col.el-col-8 {
    padding-right: 15px;
  }
}
.centen {
  height: 48px;
  margin-bottom: 20px;
  background-color: #fff;
  .el-col.el-col-2 {
    height: 100%;
    .el-button {
      width: 100%;
      height: 100%;
      border: 0px;
    }
  }
}
.button {
  background-color: #fff;
  padding: 20px;
}
</style>